<?php


namespace app\api\controller\xilumarket;

use app\common\controller\XilumarketApi;
use app\common\model\xilumarket\Product as ProductModel;
use app\common\model\xilumarket\Recovery AS RecoveryModel;
use think\Exception;

/**
 * 回收商品
 * @package app\api\controller\xilumarket
 */
class Recovery extends XilumarketApi
{
    protected $noNeedLogin = ['lists','list2'];
    protected $noNeedRight = ['*'];



    /**
     * 新增闲置
     */
    public function add(){
        $params = $this->request->param('');
        try {
            $ret = ProductModel::recovery($params,$this->auth->id);
        }catch (Exception $e){
            $this->error($e->getMessage());
        }
        $this->success('查询成功',$ret);
    }

    /**
     * 回收商品列表
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function lists(){
        $params = $this->request->param("");
        $params['city_id'] = $this->cityid;
        $lists = \app\common\model\xilumarket\Product::recoveryLists($params,$this->auth->id);
        $this->success("查询成功",$lists);
    }

    /**
     * 回收商品列表
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function mylists(){
        $params = $this->request->param("");
        $lists = \app\common\model\xilumarket\Product::myRecoveryLists($params,$this->auth->id);
        $this->success("查询成功",$lists);
    }

    /**
     * 上下架
     */
    public function multi_status(){
        $params = $this->request->param('');
        try {
            $ret = ProductModel::multiStatus($params,$this->auth->id);
        }catch (Exception $e){
            $this->error($e->getMessage());
        }
        $this->success('查询成功',$ret);
    }

    /**
     * 我的商品删除
     */
    public function del(){
        $params = $this->request->param('');
        try {
            $result = ProductModel::del($params,$this->auth->id);
        }catch (Exception $e){
            $this->error($e->getMessage());
        }

        $this->success('删除成功');
    }

    /**
     * 回收商品列表
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function lists2(){
        $category_id = $this->request->param("category_id");
        $brand_id = $this->request->param("brand_id");
        $category_ids = \app\common\model\xilumarket\RecoveryCategory::where('id',$category_id)->value('path');
        $lists = RecoveryModel::field("*")->where('status','normal')->whereIn('category_id',$category_ids)->where('brand_id',$brand_id)->order('weigh','desc')->select();
        $this->success("查询成功",$lists);
    }


}